// Package sqlgen_test contains tests for the sqlgen package
package sqlgen_test

import (
	"git.sr.ht/~mil/mobsql/sqlgen"
	"testing"
)

func Test_GenerateLoadColumnSpecSQL(t *testing.T) {
	testCases := []struct {
		Input  sqlgen.LoadColumn
		Output string
	}{
		{
			Input:  sqlgen.LoadColumn{Column: "foo", DType: sqlgen.DTypeText},
			Output: "'foo' text",
		},
		{
			Input:  sqlgen.LoadColumn{Column: "bar", DType: sqlgen.DTypeInt},
			Output: "'bar' int",
		},
		{
			Input:  sqlgen.LoadColumn{Column: "foo", DType: sqlgen.DTypeText, Required: true},
			Output: "'foo' text not null",
		},
		{
			Input:  sqlgen.LoadColumn{Column: "foo", DType: sqlgen.DTypeInt, Enum: []int{4, 7, 9}},
			Output: "'foo' int check(foo in (4,7,9))",
		},
		{
			Input:  sqlgen.LoadColumn{Column: "foo", DType: sqlgen.DTypeInt, Check: "custom sql check logic"},
			Output: "'foo' int check(custom sql check logic)",
		},
		{
			Input:  sqlgen.LoadColumn{Column: "foo", DType: sqlgen.DTypeInt, Required: true, Enum: []int{4, 7, 9}},
			Output: "'foo' int not null check(foo in (4,7,9))",
		},
	}

	for _, c := range testCases {
		result := sqlgen.GenerateLoadColumnSpecSQL(&c.Input)
		if c.Output != result {
			t.Fatalf(
				"Column specification %v generated output <%s>, but expected output: <%s>",
				c.Input,
				result,
				c.Output,
			)
		}
	}
}
